package com.zx.chatroom.util;

import com.zx.framework.core.util.DateTimeUtil;
import com.zx.framework.core.util.SecurityUtil;

import java.util.Date;

public class AESUtil {

	private static final String REGEX = ":P:";
	/**
	 * 自定义加密
	 * @param sSrc
	 * @return
	 */
	public static String encryptAES(String sSrc){
		StringBuffer src = new StringBuffer();
		Date date = new Date();
		src.append(DateTimeUtil.dateToString(date, "ssmmHHddMMyyyy"));
		src.append(REGEX);
		src.append(DateTimeUtil.dateToString(date, "HHyyyymmMMddss"));
		src.append(REGEX);
		src.append(sSrc);
		src.append(REGEX);
		src.append(DateTimeUtil.dateToString(date, "yyyyHHMMmmddss"));
		src.append(REGEX);
		src.append(DateTimeUtil.dateToString(date, "yyyyMMddHHmmss"));
		return SecurityUtil.encryptAES(src.toString());
	}
	/**
	 * 自定义解密
	 * @param sSrc
	 * @return
	 */
	public static String decryptAES(String sSrc){
		try {
			return SecurityUtil.decryptAES(sSrc).split(REGEX)[2];
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}
